﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.DomainLayer;
using HA.ModFlow.Infrastructure;

using HAUtil;


namespace HA.Data
{
    [Serializable]
   public class DSGrid3d
    {


        //public DSGrid3d(string id,DataSetReader reader)
        //{

        //    this._reader = reader;

        //    _lstValue = new List<CellCenterDataSet3d>();

        //    this._lazyLoad = true;
 
        //}


        public DSGrid3d(string id, List<CellCenterDataSet3d> lstDataSet)
        {

            this._id = id;

            this._name = id;


            this._lstValue = lstDataSet;

            this._lazyLoad = false;

            if (lstDataSet.Count > 0)
            {
                this.ComputeMinMax();
            }

        }

        string _id;

        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }


        #region 属性

        List<CellCenterDataSet3d> _lstValue;

        public List<CellCenterDataSet3d> LstValue
        {
            get { return _lstValue; }
            
        }


        public int Count
        {
            get { return this._lstValue.Count; }
        }


        public bool IsMultiDataset
        {

            get {

                if (_lstValue.Count > 1)
                {
                    return true;

                }

                else
                {
                    return false;
                }
            }
   
        }


        double _min;
        /// <summary>
        /// 求得逐步值整体的最大最小值
        /// </summary>
        public double Min
        {
            get { return _min; }
            set { _min = value; }
        }

        double _max;


        /// <summary>
        /// 数据集的最大值
        /// </summary>
        public double Max
        {
            get { return _max; }
            set { _max = value; }
        }


        protected void ComputeMinMax()
        {

            double min = double.MaxValue ;
            double max = double.MinValue ;

            foreach (CellCenterDataSet3d item in this._lstValue)
            {
                if (item.MinValue<min)
                {
                    min = item.MinValue;
                    
                }

                if (item.MaxValue>max)
                {
                    max = item.MaxValue;
                }
                
            }

            this.Min = min;
            this.Max = max;


 
        }


        public CellCenterDataSet3d GetDataSet(int index)
        {
            if (this._lstValue.Count>index)
            {

                return this._lstValue[index];
            }

            return null;
 
        }


     



        DataSetReader _reader;



        bool _lazyLoad = false;

        /// <summary>
        /// 是否延时加载数据
        /// </summary>
        public bool LazyLoad
        {
            get { return _lazyLoad; }
          
        }


        #endregion

        public void LoadData()
        {

            this._lstValue.Clear();

            List<DataSet> lst = this._reader.ReadData();

            foreach (DataSet ds in lst)
            {

                if (ds is CellCenterDataSet3d)
                {
                    this._lstValue.Add((CellCenterDataSet3d)ds);
                    
                }

            }

            this.ComputeMinMax();




 
        }


    }
}
